import java.util.ArrayList;
import java.util.List;
public class Snippet {
    public static List<Integer> subArraySumItem(int[] params) {
        int currentSum = 0;
        int curStart = 0;
        int maxSum = 0;
        int start = 0;
        int end = 0;
        for (int i = 0; i < params.length; i++) {
            currentSum += params[i];
            if (currentSum > 0) {
                if (currentSum > maxSum) {
                    maxSum = currentSum;
                    start = curStart;
                    end = i;
                }
            } else {
                currentSum = 0;
                curStart = i;//i=2

            }
        }
        List<Integer> list = new ArrayList<Integer>();
        for (int i = start + 1; i <= end; i++) {
            list.add(params[i]);
        }
        return list;
    }


    private static int getMaxSum(int[] arr) {
        int max = -100000;
        for (int i = 0; i < arr.length; i++) {
            int sum = 0;
            for (int j = i; j < arr.length; j++) {
                sum += arr[j];
                if (max < sum) {
                    max = sum;
                }
            }
        }

        return max;
    }

    public static void main(String[] args) {
        int[] arrays = new int[]{-2, 2, -3, 4, -1, 2, 1, -5, 3};
        int maxSum = getMaxSum(arrays);
        System.out.println("最大子数组的和为：" + maxSum);

    }
}
